package mygame;

import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;

/**
 * Cares for the mapping between keyboard an actions.
 * @author Aicher
 * @version 0.0.2
 */
public class KeyMapping {
    // plane steering keys
    public static final String MOVE_PLANE_ROLL_LEFT = "mvp_rll";
    public static final String MOVE_PLANE_ROLL_RIGHT = "mvp_rlr";
    public static final String MOVE_PLANE_YAW_LEFT = "mvp_yal";
    public static final String MOVE_PLANE_YAW_RIGHT = "mvp_yar";
    public static final String MOVE_PLANE_PITCH_DOWN = "mvp_pid";
    public static final String MOVE_PLANE_PITCH_UP = "mvp_piu";
    
    // plane acceleration keys
    public static final String ACCELERATE_PLANE_0 = "acp_0";
    public static final String ACCELERATE_PLANE_1 = "acp_1";
    public static final String ACCELERATE_PLANE_2 = "acp_2";
    public static final String ACCELERATE_PLANE_3 = "acp_3";
    public static final String ACCELERATE_PLANE_4 = "acp_4";
    public static final String ACCELERATE_PLANE_5 = "acp_5";
    public static final String ACCELERATE_PLANE_6 = "acp_6";
    public static final String ACCELERATE_PLANE_7 = "acp_7";
    public static final String ACCELERATE_PLANE_8 = "acp_8";
    public static final String ACCELERATE_PLANE_9 = "acp_9";
    public static final String ACCELERATE_PLANE_10 = "acp_10";
    
    // cam steering keys
    public static final String MOVE_CAM_TURN_RIGHT = "mvc_trr";
    public static final String MOVE_CAM_TURN_LEFT = "mvc_trl";
    public static final String MOVE_CAM_PITCH_UP = "mvc_ptu";
    public static final String MOVE_CAM_PITCH_DOWN = "mvc_ptd";
    public static final String MOVE_CAM_MOVE_UP = "mvc_mvu";
    public static final String MOVE_CAM_MOVE_DOWN = "mvc_mvd";
    public static final String MOVE_CAM_MOVE_LEFT = "mvc_mvl";
    public static final String MOVE_CAM_MOVE_RIGHT = "mvc_mvr";
    public static final String MOVE_CAM_MOVE_FORWARD = "mvc_mvf";
    public static final String MOVE_CAM_MOVE_BACK = "mvc_mvb";
    
    /**
     * Maps the command values to the keys and registeres the trigger in the input
     * manager.
     * @param inputManager Reference to the inputManager of the game
     * @param actionListener  Reference to the actionListener of the game
     */
    public static void doMappings(InputManager inputManager, ActionListener actionListener) {
        // basic steering of the plane (here: turns around the three axis)
        inputManager.addMapping(MOVE_PLANE_ROLL_LEFT, new KeyTrigger(KeyInput.KEY_J));
        inputManager.addListener(actionListener, MOVE_PLANE_ROLL_LEFT);
        
        inputManager.addMapping(MOVE_PLANE_ROLL_RIGHT, new KeyTrigger(KeyInput.KEY_L));
        inputManager.addListener(actionListener, MOVE_PLANE_ROLL_RIGHT);
        
        inputManager.addMapping(MOVE_PLANE_YAW_LEFT, new KeyTrigger(KeyInput.KEY_U));
        inputManager.addListener(actionListener, MOVE_PLANE_YAW_LEFT);
        
        inputManager.addMapping(MOVE_PLANE_YAW_RIGHT, new KeyTrigger(KeyInput.KEY_O));
        inputManager.addListener(actionListener, MOVE_PLANE_YAW_RIGHT);
        
        inputManager.addMapping(MOVE_PLANE_PITCH_DOWN, new KeyTrigger(KeyInput.KEY_I));
        inputManager.addListener(actionListener, MOVE_PLANE_PITCH_DOWN);
        
        inputManager.addMapping(MOVE_PLANE_PITCH_UP, new KeyTrigger(KeyInput.KEY_K));
        inputManager.addListener(actionListener, MOVE_PLANE_PITCH_UP);
        
        // accelerate plane
        inputManager.addMapping(ACCELERATE_PLANE_0, new KeyTrigger(KeyInput.KEY_0));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_0);
        
        inputManager.addMapping(ACCELERATE_PLANE_1, new KeyTrigger(KeyInput.KEY_1));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_1);
        
        inputManager.addMapping(ACCELERATE_PLANE_2, new KeyTrigger(KeyInput.KEY_2));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_2);
        
        inputManager.addMapping(ACCELERATE_PLANE_3, new KeyTrigger(KeyInput.KEY_3));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_3);
        
        inputManager.addMapping(ACCELERATE_PLANE_4, new KeyTrigger(KeyInput.KEY_4));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_4);
        
        inputManager.addMapping(ACCELERATE_PLANE_5, new KeyTrigger(KeyInput.KEY_5));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_5);
        
        inputManager.addMapping(ACCELERATE_PLANE_6, new KeyTrigger(KeyInput.KEY_6));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_6);
        
        inputManager.addMapping(ACCELERATE_PLANE_7, new KeyTrigger(KeyInput.KEY_7));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_7);
        
        inputManager.addMapping(ACCELERATE_PLANE_8, new KeyTrigger(KeyInput.KEY_8));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_8);
        
        inputManager.addMapping(ACCELERATE_PLANE_9, new KeyTrigger(KeyInput.KEY_9));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_9);
        
        inputManager.addMapping(ACCELERATE_PLANE_10, new KeyTrigger(KeyInput.KEY_P));
        inputManager.addListener(actionListener, ACCELERATE_PLANE_10);
        
        
        // cam movements
        inputManager.addMapping(MOVE_CAM_TURN_RIGHT, new KeyTrigger(KeyInput.KEY_RIGHT));
        inputManager.addListener(actionListener, MOVE_CAM_TURN_RIGHT);
        
        inputManager.addMapping(MOVE_CAM_TURN_LEFT, new KeyTrigger(KeyInput.KEY_LEFT));
        inputManager.addListener(actionListener, MOVE_CAM_TURN_LEFT);
        
        inputManager.addMapping(MOVE_CAM_PITCH_UP, new KeyTrigger(KeyInput.KEY_UP));
        inputManager.addListener(actionListener, MOVE_CAM_PITCH_UP);
        
        inputManager.addMapping(MOVE_CAM_PITCH_DOWN, new KeyTrigger(KeyInput.KEY_DOWN));
        inputManager.addListener(actionListener, MOVE_CAM_PITCH_DOWN);
        
        inputManager.addMapping(MOVE_CAM_MOVE_UP, new KeyTrigger(KeyInput.KEY_E));
        inputManager.addListener(actionListener, MOVE_CAM_MOVE_UP);
        
        inputManager.addMapping(MOVE_CAM_MOVE_DOWN, new KeyTrigger(KeyInput.KEY_D));
        inputManager.addListener(actionListener, MOVE_CAM_MOVE_DOWN);
        
        inputManager.addMapping(MOVE_CAM_MOVE_LEFT, new KeyTrigger(KeyInput.KEY_A));
        inputManager.addListener(actionListener, MOVE_CAM_MOVE_LEFT);
        
        inputManager.addMapping(MOVE_CAM_MOVE_RIGHT, new KeyTrigger(KeyInput.KEY_S));
        inputManager.addListener(actionListener, MOVE_CAM_MOVE_RIGHT);
        
        inputManager.addMapping(MOVE_CAM_MOVE_FORWARD, new KeyTrigger(KeyInput.KEY_W));
        inputManager.addListener(actionListener, MOVE_CAM_MOVE_FORWARD);
        
        inputManager.addMapping(MOVE_CAM_MOVE_BACK, new KeyTrigger(KeyInput.KEY_Y));
        inputManager.addListener(actionListener, MOVE_CAM_MOVE_BACK);
    }
}
